package com.example.demo.mapper;



import com.example.demo.model.Order;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.session.RowBounds;

import java.util.ArrayList;
import java.util.List;
@Mapper
public interface OrderMapper {
    @Select("select * from ordertbl order by id")
    List<Order> findAllWithRowBounds(RowBounds rowBounds);

    @Select("select * from ordertbl order by id ")
    List<Order> findAllWithParam(@Param("pageNum") int pageNum,
                                  @Param("pageSize") int pageSize);

    @Delete("delete from ordertbl where customer = #{customer}")
    int delete(Order order);
    @Insert("insert into ordertbl (customer,coffeeid,state,create_time,update_time)values (#{customer},#{coffeeid},#{state},now(),now())")
    @Options(useGeneratedKeys = true)
    int save(Order order) ;
    @Select("select o.id id,o.customer customer,c.name name,o.state state,o.create_time create_time,o.update_time update_time from ordertbl o left join coffee c on o.coffeeid = c.id where o.customer = #{customer}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "customer",property = "customer"),
            @Result(column = "name",property = "name"),
            @Result(column = "state",property = "state"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
    })
    ArrayList<Order> findByCustomer(@Param("customer") String customer);
    @Update("update ordertbl set state = #{state},update_time = now() where id = #{id}")
    int update(Order order) ;
}
